var uid =parseInt(getParameter("uid"));//推荐人id
var grade =parseInt(getParameter("grade"));//推荐人级别 0：代表平台 1：一级合伙人 2：二级合伙人
var m=getParameter("m");//p:发展合伙人 u:发展用户

function initUI() {
    showLoadingPage();

    if(checkParameter()){
        var Img = new Image();
        if(grade==0){
            if(m=="p"){
                Img.src = "https://api.qrserver.com/v1/create-qr-code/?size=480x480&data=http://pocket.all-star.top/home/partner?partner_id="+uid+"%26grade=0";
            }
            else {
                Img.src = "https://api.qrserver.com/v1/create-qr-code/?size=480x480&data=http://pocket.all-star.top/user/mobilebind?partner_id="+uid;
            }
        }
        else if(grade==1){
            if(m=="p"){
                Img.src = "https://api.qrserver.com/v1/create-qr-code/?size=480x480&data=http://pocket.all-star.top/home/partner?partner_id="+uid+"%26grade=1";
            }
            else {
                Img.src = "https://api.qrserver.com/v1/create-qr-code/?size=480x480&data=http://pocket.all-star.top/user/mobilebind?partner_id="+uid;
            }
        }
        else {
            Img.src = "https://api.qrserver.com/v1/create-qr-code/?size=480x480&data=http://pocket.all-star.top/user/mobilebind?partner_id="+uid;
        }

        Img.onload = function ()
        {
            $("#qr_img").append(Img);
            hideLoadingPage();
            $("#main_page").fadeIn(300);
        }
    }
}

function initData() {
    if(isNaN(uid))
    {
        uid=0;
    }

    if(isNaN(grade))
    {
        grade=-1;
    }
}

function addEvent() {

}

function checkParameter() {
    if(uid == undefined || uid == null || isNaN(uid) || uid<0){
        showAlert("对不起,无推荐人信息");
        return false;
    }
    return true;
}

function updateInviteOpenNum(){
    $.ajax({
        type: "get",
        url: "/v1/wx-user/update-invite-open-num",
        data: {uid:uid},
        dataType: "json",
        beforeSend:function(){

        },
        success: function(data){
            if(data.code=="success") {

            }
        },
        error: function(){
        }
    });
}

//展示加载页面
function showLoadingPage() {
    $(".page").hide();
    $("#page_loading").fadeIn(300);
}

//隐藏加载页面
function hideLoadingPage() {
    $("#page_loading").fadeOut(300);
}



$(function () {
    initData();
    initUI();
    addEvent();
    updateInviteOpenNum();
});

